home *** CD-ROM | disk | FTP | other *** search
-
- int mouseid ;The creature id of mouse so warblers can find the mouse.
- int mouserad ;Radius of mouse. Gets bigger every other warbler you eat.
- int warblers ;Number of warblers alive. If it gets down to zero you win!
-
- ;When a warbler goes offscreen it comes back on the other side. Here are
- ;two functions that help implement this 'wrap around'.
-
- to wrapx(x)
- {
- if (x > 320+50) ; off screen 50 to the right?
- x = -50; ; then move it to left of screen
- if (x < -50) ; off screen 50 to the left?
- x = 320+50 ; then move it to right of screen
- return(x)
- }
-
- to wrapy(y)
- {
- if (y > 200+50)
- y = -50
- if (y < -50)
- y = 200+50
- return(y)
- }
-
- ;Here is the code for the warbler creature. This is the 'brains' of the
- ;program. The warblers take care of pulsating themselves, and also
- ;see if they are having a run-in with the mouse.
-
- ;The pulsating circle creature.
- creature warbler
- {
- int csize ;current size
- int dsz ;rate of change of size
- int cmax ;maximum size
- int cmin ;minimum size
- int color ;color of this warbler
- int md ;used to hold distance to mouse
-
- ;1st time through randomly initialize some of our variables
- if (Cnew) ;Cnew is true only first time a warbler is Evolve()'d
- {
- cmin = Random(5)+2; ;min radius
- cmax = Random(16)+5 ;max radius
- dsz = Random(3)+1 ;speed of radius change
- if (Random(1)) ;randomly make it start out shrinking or growing
- dsz = -dsz;
- csize = (cmin + cmax )/2 ;start 1/2 way through size cycle
- color = Random(4)+1 ;color random between 1 and 4
- }
-
- ;Do stuff to figure out what size warbler is this frame
- if (!(Cage&31)) ;every 32 ticks increase max radius size by 1
- cmax = cmax+1
- csize = csize + dsz
- if (csize > cmax || csize < cmin) ;if hit min or max reverse delta radius
- {
- dsz = -dsz
- }
-
- ;Move warbler by adding its speed to its position, and piping through
- ;a 'wrap' function in case result is off-screen.
- Cx = wrapx(Cx + Cdx) ;Cx and Cdx are passed from the 'Spawn' call below.
- Cy = wrapy(Cy + Cdy)
-
- ;Interact with the mouse creature.
- if (mouseid) ;if the mouse creature is still alive...
- {
- ;find distance to mouse
- md = Distance(Creaturex(mouseid),Creaturey(mouseid), Cx, Cy)
- ;if inside mouse radius, suicide
- if (md < mouserad && csize < mouserad)
- {
- if (warblers&1) ;every other warbler increment mouse radius
- mouserad = mouserad+1
- Kill(cid);
- warblers = warblers - 1
- return;
- }
- ;if mouse inside our radius kill it
- if (md < csize && csize > mouserad)
- {
- Kill(mouseid);
- mouseid = 0;
- }
- }
- Circle(Cx,Cy,csize,color) ;draw ourselves
- }
-
-
- ;The mouse creature is quite simple since it doesn't need to figure out
- ;whether it has hit a warbler or not. It just calls the built in Mouse
- ;functions to set its current position on the screen (Cx and Cy), and
- ;draws a disk in color 13.
-
- creature mouse
- {
- Cx = MouseX()
- Cy = MouseY()
- Disk(Cx,Cy,mouserad,13)
- }
-
- ;Finally there's the 'main code' for the game:
-
- loop ;repeat forever (or until user doesn't want to play again)
- {
- KillAll() ;Kill any creatures left from last game
- mouserad = 8 ;mouse starts with 8 pixel radius
- mouseid = Spawn(mouse,0,0,0,0) ;make the mouse
- for warblers = 0 to 12 ;make 13 warblers
- {
- int ix,iy
- ix = Random(6)-3 ;speed from -3 to 3
- if (ix == 0) ;don't allow 0 x speed
- ix = 1
- iy = Random(6)-3
- if (iy == 0)
- iy = 1
- ;make a warbler at random position on screen and
- ;random speed between -3 and 3
- Spawn(warbler, Random(320), Random(200), ix, iy)
- }
- PreSwap() ;Set up for double buffering
-
- ;here's the main game loop. Keep going as long as there's
- ;warblers alive and the mouse is alive too.
- while (mouseid && warblers>0)
- {
- ClearScreen() ;set screen quickly to black
- Evolve() ;let all creatures live one tick
- Swap() ;swap drawing screen and viewing screen
- }
-
- ToText() ;back into text mode
- Prints(StrNum(warblers) + " Warblers left");
- if (warblers <= 0)
- {
- Prints("You won!!!")
- }
- Prints("Play again? (y/n)")
- int key ;oops, need another variable...
- key = WaitKey()
- if (key == 'n' || key == 'N')
- break
- }
-
-